import 'package:shared_preferences/shared_preferences.dart';

String prefsKeyIsFirstLaunch = "isFirstLaunch";

class AppPrefs {
  static SharedPreferences? _instance;

  static init() async {
    if (_instance == null) {
      _instance = await SharedPreferences.getInstance();
    }
  }

  // 是否是第一次启动
  static bool isFirstLaunch() {
    bool? value = _instance!.getBool(prefsKeyIsFirstLaunch);
    if (value == null) {
      value = true;
    }
    return value;
  }

  static setIsFirstLaunch(bool isFirstLaunch) {
    return _instance!.setBool(prefsKeyIsFirstLaunch, isFirstLaunch);
  }

  static setString(String key, String value) => _instance!.setString(key, value);

  static String? getString(String key) => _instance!.getString(key);

  static removeKey(String key) => _instance!.remove(key);
}
